#include <mc9s12dp512.h>     /* derivative information */

void init_adc(void)
{
	ATD0CTL2 = 0x80; // power up
	ATD0CTL3 = 0x80; // one sample
	ATD0CTL4 = 0x05; // 10 bit result
}

/*
   This returns the value of a certain adcchannel

   channel -- the channel number (0-7)
   */
unsigned short adc_sample(unsigned char channel)
{
	ATD0CTL5 = 0x80 | channel;
	while((ATD0STAT1&0x01) == 0);

	return ATD0DR0;
}
